#!/bin/bash
export LANG=us.UTF-8

FTP_HOST="10.12.190.7"
FTP_USERNAME="webftpuser"
FTP_PASSWORD="123456"
#FTP_REMOTE_DIR="/var/log/weblog"
BMM_NUMBER=`echo $(hostname)|cut -d '.' -f 1`;

DATE_STR=$(date -d "1 day ago" +"%Y-%m-%d")
TO_DEL_DATE=$(date -d "20 day ago " +"%Y-%m-%d")

local_log_name="/opt/apache-tomcat-7.0.6/logs/localhost_access_log.$DATE_STR.txt"
remote_log_name="access_log_${BMM_NUMBER}-${DATE_STR}.txt";

lftp  <<EOF
open $FTP_HOST
user $FTP_USERNAME $FTP_PASSWORD
cd
put $local_log_name -o $remote_log_name
echo "upload ok at $(date +"%Y-%m-%d" )">/home/weblog.log
bye
EOF


if [ -e "/opt/apache-tomcat-7.0.6/logs/localhost_access_log.$TO_DEL_DATE.txt" ]
then
        rm -rf "/opt/apache-tomcat-7.0.6/logs/localhost_access_log.$TO_DEL_DATE.txt";
fi
